import React from 'react';
import { Redirect } from 'react-router-dom';

import LoginForm from './LoginForm';
import memory from '../../utils/memoryUtils';

import './index.less';
import icon from '../../assets/images/icon.png';

/**
 * 登录的路由组件
 *
 * @export
 * @class Login
 * @extends {Component}
 */
export default function Login(props) {
    React.useEffect(() => {
        document.title = '登录';
    }, []);

    // 登录状态检查，若已登录，跳转到管理界面
    const { user } = memory;

    if (user && user._id) {
        return <Redirect to="/" />
    }

    return (
        <div className="login">
            <header>
                <img className="icon" src={icon} alt="商城" />
                <h1 className="title">GULI-Mall</h1>
            </header>
            <div className="form">
                <h2>用户登录</h2>
                <LoginForm history={props.history} />
            </div>
        </div>
    )
}

